package goodmemo.server;

import javax.xml.bind.annotation.XmlRootElement;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

@XmlRootElement
public class MemoEntry{
    private long mtime;
    private long memoId;
    private long sender;
    private List<Long> receivers;
    private String memo;

    public MemoEntry(){}
    public MemoEntry( long memoId, long sender, String memo, long mtime) {
        this(memoId,sender,null,memo,mtime);
    }
    public MemoEntry( long memoId, long sender, List<Long> receivers, String memo) {
        this(memoId,sender,receivers,memo,0);
    }
    public MemoEntry( long memoId, long sender, List<Long> receivers, String memo,long mtime) {

        this.mtime = mtime;
        this.sender = sender;
        this.receivers = receivers;
        this.memo = memo;
        this.memoId = memoId;
    }
    public long getMemoId() {
        return memoId;
    }

    public long getSender() {
        return sender;
    }

    public List<Long> getReceivers() {
        return receivers;
    }

    public String getMemo() {
        return memo;
    }

    public long getMtime() {
        return mtime;
    }

    public void setMemoId(long memoId) {
        this.memoId = memoId;
    }

    public void setSender(long sender) {
        this.sender = sender;
    }

    public void setReceivers(List<Long> receivers)
    {
        this.receivers = receivers;
    }

    public void setMemo(String memo) {
        this.memo = memo;
    }

    public void setMtime(long mtime){
        this.mtime = mtime;
    }

    public String toString(){

        String receiversStr = null;
        if (receivers != null){
            receiversStr = StringUtils.join(
                        receivers.listIterator()," ");
        } else{
            receiversStr = "";
        }

        return String.format("memoId=%d,sender=%d,"+
                "receivers=%s,memo=%s,mtime=%d",
                memoId,sender,receiversStr,memo,mtime);
    }
}
